Skip to content

test(query-persist-client-core/persist): add tests for removing an expired or busted cache in 'persistQueryClientRestore'#10876

Merged
sukvvon merged 1 commit into
mainfrom
test/query-persist-client-core-restore-invalidate-cache
Jun 4, 2026
Merged

test(query-persist-client-core/persist): add tests for removing an expired or busted cache in 'persistQueryClientRestore'#10876
sukvvon merged 1 commit into
mainfrom
test/query-persist-client-core-restore-invalidate-cache

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Jun 4, 2026

🎯 Changes

Adds unit tests for persistQueryClientRestore covering the cache invalidation paths: the persisted client is removed when the cache is older than maxAge (expired) or when its buster does not match the configured one.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for query persistence, including verification that expired cached states are properly removed and that mismatched validation values trigger correct cleanup behavior.

…pired or busted cache in 'persistQueryClientRestore'
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7fbf7328-a814-4048-a76e-054783e5d2f5

📥 Commits

Reviewing files that changed from the base of the PR and between e6c26c0 and fb27fb8.

📒 Files selected for processing (1)
  • packages/query-persist-client-core/src/__tests__/persist.test.ts

📝 Walkthrough

Walkthrough

This PR adds two test cases to persistQueryClientRestore in persist.test.ts. The tests verify that persister.removeClient is called when cached data expires via maxAge or when the buster value mismatches the provided option.

Changes

persistQueryClientRestore invalidation tests

Layer / File(s) Summary
Tests for expired cache and buster mismatch
packages/query-persist-client-core/src/__tests__/persist.test.ts
Two new test cases added: one asserts persister.removeClient is called when persisted cache exceeds maxAge; the other asserts removal when the persisted buster value differs from the provided buster option. Both stub persister.restoreClient and verify the removal behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • TanStack/query#10875: Reorganized the persist test structure for the same persistQueryClientRestore function.
  • TanStack/query#10874: Modifies persistQueryClientRestore tests by stubbing persister.restoreClient and asserting persister.removeClient behavior.
  • TanStack/query#10872: Adds persistQueryClientRestore test coverage validating the happy path where valid cache prevents removeClient invocation.

Poem

🐰 Cache grows stale, the buster calls foul,
So we test the cleanup with whiskers and howl—
When maxAge expires or keys disagree,
removeClient springs free, as tests prove it'll be!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: adding tests for cache invalidation in persistQueryClientRestore.
Description check ✅ Passed The description follows the repository template, includes all required sections with relevant details about the changes, and properly marks the release impact as dev-only.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/query-persist-client-core-restore-invalidate-cache

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 4, 2026

View your CI Pipeline Execution ↗ for commit fb27fb8

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-04 03:19:38 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@sukvvon sukvvon self-assigned this Jun 4, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 4, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10876

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10876

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10876

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10876

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10876

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10876

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10876

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10876

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10876

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10876

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10876

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10876

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10876

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10876

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10876

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10876

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10876

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10876

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10876

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10876

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10876

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10876

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10876

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10876

commit: fb27fb8

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

size-limit report 📦

Path Size
react full 12.11 KB (0%)
react minimal 9.08 KB (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant